﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using EHRForce.Models;
using EHRForce.Helpers;


namespace EHRForce.Controllers
{
    public class RegistrationController : Controller
    {
        PatientRepository patientRepository = new PatientRepository();

        //
        // GET: /Registration/
        // Search for Patients
        // Recent Patients List

        public ActionResult Index(int? page)
        {
            const int pageSize = 25;

            var patients = patientRepository.FindAllPatients();
            var paginatedPatients = new PaginatedList<Patient>(patients,
                                                               page ?? 0,
                                                               pageSize);

            return View(paginatedPatients);
        }

        //
        // GET: /Registration/New

        public ActionResult New()
        {
            Patient patient = new Patient()
            {
                LastName = "Unknown"
            };
            return View(new PatientFormViewModel(patient));
        } 

        //
        // POST: /Registration/New

        [HttpPost]
        public ActionResult New(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /Registration/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Registration/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

    }
}
